package com.qdlc.p2p.manage.action.additional;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.common.enums.EnumUploadImgType;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import org.apache.struts2.convention.annotation.Action;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 51ky on 2016/5/26.
 */
public class ManageBannerAction extends BaseAction implements ModelDriven {

    private Map<String, Object> data;

    private final String REGISTERED_ACTIVITY_BANNER = "registeredActivityBanner";

    private final String LOGIN_ACTIVITY_BANNER = "loginActivityBanner";

    private final String INVEST_ACTIVITY_BANNER = "investActivityBanner";

    /**
     *  活动图片管理页面
     *
     * @return
     * @throws Exception
     */
    @Action(value = "/modules/column/banner/bannerManager")
    public String bannerManager() throws Exception {
        return "bannerManager";
    }

    /**
     *
     *
     * @return
     * @throws Exception
     */
    @Action(value = "/modules/column/banner/bannerAdd")
    public String bannerAdd() throws Exception {
        request.setAttribute("webUrl", SystemConfigHelper.getValue(SystemConfigHelper.Nid.IMAGE_SERVER_URL));
        return "bannerAdd";
    }

    /**
     * 添加banner
     *
     * @return
     * @throws Exception
     */
    @Action(value = "/modules/column/banner/addBanner")
    public void addBanner() throws Exception {
        data = new HashMap<String, Object>();
        String bannerName = paramString("bannnerName");
        String webUrl = SystemConfigHelper.getValue(SystemConfigHelper.Nid.IMAGE_SERVER_URL);
        String picPath = imgUploadToWeb(EnumUploadImgType.AUDITION.getValue(),bannerName,webUrl);
        if (StringUtil.isNotEmpty(picPath)) {
            data.put("result", true);
            data.put("webUrl",webUrl);
            data.put("picPath",picPath);
            data.put("msg", "上传成功！");
        }
        else{
            data.put("result", false);
            data.put("msg", "上传失败！");
        }
        printHtml(getStringOfJpaObj(data));
    }

}
